using Microsoft.Extensions.DependencyInjection;
using NLog.Extensions.Logging;
using NLog.Targets;
using System;

// public static class NLogServiceCollectionExtensions
// {
    public static IServiceCollection AddNLogging(this IServiceCollection service)
    {
        //定义日志文件路径
        var fileFullName = System.IO.Path.Combine(System.Environment.CurrentDirectory, "sk-log.log");
        var fileTarget = new FileTarget
        {
            FileName = fileFullName
        };

        //定义控制台显示
        var consoleTarget = new ConsoleTarget();

        //新建日志配置
        var config = new NLog.Config.LoggingConfiguration();
        //添加日志规则
        config.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, fileTarget);

        //注册日志
        service.AddLogging(logBuilder => logBuilder.AddNLog(config));

        return service;
    }
// }
